package com.rxt.service.impl;

import com.rxt.common.result.Result;
import com.rxt.model.domain.QAnswer;
import com.rxt.mapper.QAnswerMapper;
import com.rxt.model.vo.QAnswerVo;
import com.rxt.service.IQAnswerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rxt.service.IQQuestionService;
import com.rxt.util.BaseContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 周梓文
 * @since 2023-08-24
 */
@Service
public class QAnswerServiceImpl extends ServiceImpl<QAnswerMapper, QAnswer> implements IQAnswerService {

    @Lazy
    @Autowired
    private IQQuestionService iqQuestionService;

    @Override
    public Result answer(QAnswerVo qAnswerVo) {

        QAnswer qAnswer = new QAnswer();

        qAnswer.setExpertId(BaseContext.get().getId());
        qAnswer.setExpert(BaseContext.get().getRealName());
        qAnswer.setContent(qAnswerVo.getContent());
        qAnswer.setQuestionId(qAnswerVo.getQuestionId());

        this.save(qAnswer);

        //TODO 待优化
        //修改question的状态为    已回答
        iqQuestionService.updateStatusTo_1_ById(qAnswerVo.getQuestionId());

        return Result.ok(qAnswer);
    }
}
